﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace MyWeb.Data
{
	public class tblNewsDAL : SqlDataProvider
	{

		#region[tblNews_GetbyAll]
		public DataTable tblNews_GetByAll()
		{
			using (var cmd = new SqlCommand("sp_tblNews_GetByAll", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[tblNews_GetbyId]
		public DataTable tblNews_GetById(tblNewsInfo Data)
		{
			using (var cmd = new SqlCommand("sp_tblNews_GetById", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_nid", Data._nid));
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[tblNews_GetbyTop]
		public DataTable tblNews_GetByTop(string Top, string Where, string Order)
		{
			using (var cmd = new SqlCommand("sp_tblNews_GetByTop", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				cmd.Parameters.Add(new SqlParameter("@Top",Top));
				cmd.Parameters.Add(new SqlParameter("@Where",Where));
				cmd.Parameters.Add(new SqlParameter("@Order",Order));
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[tblNews_Insert]
		public void tblNews_Insert(tblNewsInfo Data)
		{
			using (var cmd = new SqlCommand("sp_tblNews_Insert", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_ntitle", Data._ntitle));
				cmd.Parameters.Add(new SqlParameter("@_ncontent", Data._ncontent));
				cmd.Parameters.Add(new SqlParameter("@_ncreatedate", Data._ncreatedate));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[tblNews_Update]
		public void tblNews_Update(tblNewsInfo Data)
		{
			using (var cmd = new SqlCommand("sp_tblNews_Update", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_nid", Data._nid));
				cmd.Parameters.Add(new SqlParameter("@_ntitle", Data._ntitle));
				cmd.Parameters.Add(new SqlParameter("@_ncontent", Data._ncontent));
				cmd.Parameters.Add(new SqlParameter("@_ncreatedate", Data._ncreatedate));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[tblNews_Delete]
		public void tblNews_Delete(string Data)
		{
			using (var cmd = new SqlCommand("sp_tblNews_Delete", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_nid", Data));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
	}
}